/*
 * Created on Jun 6, 2005
 *
 */
package littlecyberwar.tool;

import java.awt.*;
import java.awt.geom.Area;
import littlecyberwar.ui.*;
import littlecyberwar.util.*;

/**
 * @author Milton  Soong
 *
 */
public class DirtyAreaManager {

	static Area selectedArea = new Area();	// the union of all dirty areas
	
	/**
	 * 
	 */
	public DirtyAreaManager() {
		super();

	}

	public static void addDirtyArea( Shape shapeIn ){
		//Debug.out("--- addDirtyArea");
		Area a = new Area(shapeIn);
		selectedArea.add(a);
	}
	
	public static void reset() {
		//Debug.out("--- reset");
		selectedArea = new Area();
	}
	
	public static Rectangle getDirtyArea() {
		//Debug.out("--- getDirtyArea");
		return ( selectedArea.getBounds() );
	}
	
	public static Rectangle getAndResetDirtyArea() {
		//Debug.out("--- getAndResetDirtyArea");
		Rectangle val = selectedArea.getBounds();
		reset();
		return ( val );		
	}
	
	public static void checkAndRepaint(PlayingBoardPanel comp){
		// Debug.out("--- checkAndRepaint");
		if ( selectedArea != null ){
			// Debug.out("--- checkAndRepaint with selected area != null");
			Rectangle rec = selectedArea.getBounds();			
			Rectangle scaledRec = ScalingDelegate.getScaledRectangle(rec);
			scaledRec.grow(PlayingBoardPanel._DEFAULT_STROKE_WIDTH, PlayingBoardPanel._DEFAULT_STROKE_WIDTH);
			comp.repaint(scaledRec);
		}
		// reset();
	}

	// this will repaint just the area passed in from tha call
	public static void checkAndRepaint(PlayingBoardPanel comp, Area a){
		//Debug.out("--- checkAndRepaint passed in area");
		if ( a != null ){
			Rectangle rec = a.getBounds();			
			Rectangle unscaledRec = ScalingDelegate.getScaledRectangle(rec);
			unscaledRec.grow(PlayingBoardPanel._DEFAULT_STROKE_WIDTH, PlayingBoardPanel._DEFAULT_STROKE_WIDTH);
			comp.repaint(unscaledRec);
		}
		
	}
}
